﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Microsoft.CloudSaver.Configurator
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void cmdSaveCSCFG_Click(object sender, EventArgs e)
        {
            error.Clear();
            if (string.IsNullOrEmpty(txtEndpoint.Text)) error.SetError(txtEndpoint,
                "L'endpoint è il nome che hai scelto prima di *.core.windows.net");
            else if (string.IsNullOrEmpty(txtApi.Text)) error.SetError(txtApi,
                "La chiave di accesso è, a scelta, la Primary access key o la Secondary access key");
            else
            {

                saver.ShowDialog();
                if (!string.IsNullOrEmpty(saver.FileName))
                {
                    using (var writer = new StreamWriter(File.Create(saver.FileName)))
                    {
                        writer.Write(string.Format(ConfStuff.AzureConfiguration, txtEndpoint.Text, txtApi.Text,txtThumbprint.Text));
                    }
                    MessageBox.Show("Fatto!", "Configurazione Azure", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

       
    }
}
